*********************************************************************************
/*    Create scatter plot for revenue, cost, and revenue/cost by income		*/
*********************************************************************************
clear all

* File paths
local datapath "${mvpf_audits}/data/cleaned" 
local datapath "${mvpf_audits}/data/" 

local graphpath "${graphpath}" 

* Version of fig to produce 
global version  ${version} // paper or slides

* Other formatting
if "${version}" == "slides" {
	global title "title(" ", size(vhuge))"
	global img wmf
	graph set window fontface "Arial"
	global title "title(" ", size(vhuge))"
	global axis_size "" //xsize(6.5) ysize(4)" // makes figure wider
}

else if "${version}" == "paper" {
	global title "title("")"
	global img pdf
	graph set window fontface "LMRoman10-Regular"
	global title " "
	global axis_size " " // makes figure wider
}

/*------------------------------------------------------------------------------
Figure: Revenue/Cost by income percentile for Operational Audits (Corrected TPI)
------------------------------------------------------------------------------*/
foreach inc in "tpi_10p_cor_pctl5" "tpi_20p_cor_pctl5" {
	
	if "`inc'" == "tpi_20p_cor_pctl5" {
		use "${mvpf_audits}/data/figures_rep/ap7_b.dta", clear
	}
	
	if "`inc'" == "tpi_10p_cor_pctl5" {
		use "${mvpf_audits}/data/figures_rep/ap7_a.dta", clear
	}
	
	* set y-axis label, title, and figure name
	local ylab = "Audit Revenue / Total Costs"
	
	* Preferences 
	local symbsize small
	local textsize vsmall

	** Subgroup figure
	local fig_name = "scatter_rc_`inc'_ops"
	
	** xtitle
	if "`inc'"=="tpi_pctl5" global xtitle = "TPI percentile group"
	if "`inc'"=="tpi_10p_cor_pctl5" global xtitle = "Corrected TPI (10% Tax)"
	if "`inc'"=="tpi_20p_cor_pctl5" global xtitle = "Corrected TPI (20% Tax)"

	label define tpi_pctl_label 1 "0-5" 2 "5-10" 3 "10-15"	4 "15-20"	5 "20-25"	6 "25-30" 7 "30-35"	8 "35-40" 9 "40-45" 10 "45-50" 11 "50-55" 12 "55-60" 13 "60-65" 14 "65-70" 15 "70-75"16 "75-80"17 "80-85" 18 "85-90" 19 "90-95" 20 "95-99" 21 "99-99.9" 22 "99.9+"
	label val pctl tpi_pctl_label

	** Rev/Labor Costs
	tw (scatter rc_disc pctl if inrange(pctl, 1, 22) ,  ///
		 mcolor("${rc_col}") msymbol(S) msize(medsmall)) ///
		, ///
		ylabel(0(2)10, nogrid format(%9.0fc)) yscale(r(0 1)) ///
		yline(1, lw(thin) lp(dash) lc(gs11)) ///
		ytitle("`ylab'") xtitle("${xtitle}")   ///
		legend(off) ///
		${title} ${axis_size} ///
		xscale(r(1 22))  ///
		xlabel(1(1)22, value labsize(small) tl(.5) nogrid angle(45) )
	graph export "`graphpath'/`fig_name'.wmf", as(wmf) replace
	
}